﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Applicant.Models;
using Applicant.DAL;

namespace Applicant.Controllers
{
    public class ApplicantController : Controller
    {
        private ApplicantDataContext db = new ApplicantDataContext();

        // GET: /Applicant/
        public ActionResult Index()
        {
            return View(db.Applicant.ToList());
        }

        // GET: /Applicant/Details/5
        public ActionResult Details(int? id)
        {
            Applicants applicants = db.Applicant.Find(id);
            return View(applicants);
        }

        // GET: /Applicant/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /Applicant/Create
        [HttpPost]
        public ActionResult Create(Applicants applicants)
        {
            if (ModelState.IsValid)
            {
                db.Applicant.Add(applicants);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(applicants);
        }

        // GET: /Applicant/Edit/5
        public ActionResult Edit(int? id)
        {
            Applicants applicants = db.Applicant.Find(id);
            return View(applicants);
        }

        // POST: /Applicant/Edit/5
        [HttpPost]
        public ActionResult Edit(Applicants applicants)
        {
            if (ModelState.IsValid)
            {
                db.Entry(applicants).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(applicants);
        }

        // GET: /Applicant/Delete/5
        public ActionResult Delete(int? id)
        {
            Applicants applicants = db.Applicant.Find(id);
            return View(applicants);
        }

        // POST: /Applicant/Delete/5
        [HttpPost]
        public ActionResult Delete(int id)
        {
            Applicants applicants = db.Applicant.Find(id);
            db.Applicant.Remove(applicants);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
